package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark14Binding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class Mark14 extends BaseMark {

    LayoutWatermark14Binding binding;

    public Mark14(@NonNull Context context) {
        super(context);
    }

    public Mark14(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark14(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark14Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
        } else {
            binding = LayoutWatermark14Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding1, "title14", binding.binding1);
        setText(binding.binding7, "time14", binding.binding6);
        setTime(binding.binding7, new SimpleDateFormat("yyyy.MM.dd HH:mm"));
        setText(binding.binding3, "phone14", binding.binding2);
        setText(binding.binding5, "desc14", binding.binding4);
        setText(binding.binding9, "didian14", binding.binding8);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title14", "标题"));
        list.add(new EditItem("phone14", "联系方式"));
        list.add(new EditItem("desc14", "业务简介"));
        list.add(new EditItem("time14", "时间", true));
        list.add(new EditItem("didian14", "地点"));
        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding7, new SimpleDateFormat("yyyy.MM.dd HH:mm"));
        } else {
            super.onValueChange(item);
        }
    }

}
